package cn.wmx.sqlsession;

import cn.wmx.config.XMLConfigBuilder;
import cn.wmx.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    /**
     * 1）使用 dom4j 解析配置文件，将解析出来的配置文件封装到 Configuration 中
     * 2）创建 SqlSessionFactory 对象
     *
     * @param inputStream
     * @return
     */
    public SqlSessionFactory builder(InputStream inputStream) throws DocumentException, PropertyVetoException {
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
